#include "inc/AppGlobal.h"

static s32 formUnSaleTransmitData(SDK_8583_ST8583 *pstBag8583)
{
    if (pstBag8583 == NULL || lib8583BuildPublicField(pstBag8583, "702406C03CC09819") <= 0)
    {
        return 0;
    }

    sdk8583SetField(pstBag8583, SDK_8583_FIELD_MSG, (u8 *) "0200", 4);
    sdk8583SetField(pstBag8583, 3, (u8 *) "200000", 6);
    sdk8583SetField(pstBag8583, 25, (u8 *) "00", 2);

    return pstBag8583->nBagLen;
}

static s32 transmitUnSaleOnline(Transmit8583Data *transmitData)
{
    transmitData->mTransType = TRANS_TYPE_UNSALE;
    return lib8583TransmitById(NULL, NULL, NULL, transmitData, formUnSaleTransmitData, TRANSMIT_MODE_8583_REVERSAL);
}

s32 unSaleTrade(u16 readCardType)
{
    s32 ret = 0;

    ret = startUnSaleProcess(readCardType);

    return ret;
}

void initUnSale()
{
    platform_unsale_set_transmit_online_func((TransmitUnSaleOnlineFunc) transmitUnSaleOnline);
}